using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Comdb
/// </summary>
public class Comdb
{
	public Comdb()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static int GetCountInTable(string TableName)
    {
        string stsql;
        stsql = "SELECT count(*) as fText FROM " + TableName;
        DataTable dt;
        dt = dal.SelectTable(stsql);
        if (dt.Rows.Count > 0)
        {
            return Convert.ToInt32(dt.Rows[0]["fText"]);
        }
        return 0;
    }
    public static string GetFieldByFieldNumber(string TableName, string GetFieldName, string FieldFilter, string FieldValue)
    {
        string stsql;
        stsql = "SELECT " + GetFieldName + " as fName FROM " + TableName + " where " + FieldFilter + "=" + comm.to_sql(FieldValue, "number");
        DataTable dt;
        dt = dal.SelectTable(stsql);
        if (dt.Rows.Count > 0)
        {
            return dt.Rows[0]["fName"].ToString();
        }
        return "";
    }

    public static string GetCountryNameById(string id)
    {
        return GetFieldByFieldNumber("Countries", "CountryName", "CountryID", id);
    }

    public static string GetNewCatNameById(string id)
    {
        return GetFieldByFieldNumber("NewsCats", "CatName", "ID", id);
    }
    public static string GetPhotoCatNameById(string id)
    {
        return GetFieldByFieldNumber("PhotoCats", "CatName", "ID", id);
    }
    public static string GetProductCatNameById(string id)
    {
        return GetFieldByFieldNumber("ProductCats", "CatName", "ID", id);
    }
    public static string GetNumberOfNewsFromCatId(string id)
    {
        string sqlStr = "select count(*) from NewsContents where CatId=" + id;
        string rValue = "0";
        try
        {
            rValue = dal.ExecuteScalar(sqlStr).ToString();
        }
        catch
        {
        }
        return rValue;
    }
}
